package com.framework;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
class ComponentOutput<T> {
    private boolean success;
    private String errorCode;
    private String errorMessage;
    private T data;
    private Map<String, Object> metadata = new HashMap<>();
    
    public static <T> ComponentOutput<T> success(T data) {
        ComponentOutput<T> output = new ComponentOutput<>();
        output.setSuccess(true);
        output.setData(data);
        return output;
    }
    
    public static <T> ComponentOutput<T> failure(String errorCode, String errorMessage) {
        ComponentOutput<T> output = new ComponentOutput<>();
        output.setSuccess(false);
        output.setErrorCode(errorCode);
        output.setErrorMessage(errorMessage);
        return output;
    }
    
    public static <T> ComponentOutput<T> failure(String errorCode, String errorMessage, T data) {
        ComponentOutput<T> output = new ComponentOutput<>();
        output.setSuccess(false);
        output.setErrorCode(errorCode);
        output.setErrorMessage(errorMessage);
        output.setData(data);
        return output;
    }
}